package org.example.netty.test.nio.netty.chat.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.example.netty.test.nio.netty.chat.bean.LogoutMessage;
import org.example.netty.test.nio.netty.chat.bean.SendUserMessage;
import org.example.netty.test.nio.netty.chat.session.GlobalContent;
import org.example.netty.test.nio.netty.chat.session.UserSession;

/**
 * @author zp
 * @version 1.0
 * @description: 处理消息SendUserMessage
 * @date 2023/4/6 18:29
 */
@Slf4j
public class SendUserMessageHandler extends SimpleChannelInboundHandler<SendUserMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, SendUserMessage msg) throws Exception {
        log.debug("发送私聊的消息：{}",msg);
        GlobalContent globalContent = GlobalContent.getInstance();
        UserSession userSession = globalContent.getSession(msg.getSender());
        userSession.sendUserChatMessage(msg,ctx);
    }
}
